<template>
  <div class="recommendList">
    <!-- 右上推荐人 -->
    <div v-for="(item, index) in classData" :key="index" class="recommendItem">
      <div class="recommend" @click="gotoMypage(item)">
        <!-- <img :src="item.face" alt="" class="header-img" /> -->
        <Avatar
          class="header-img"
          shape="circle"
          @on-error="
            (val) =>
              (val.target.src = require('@/assets/communityimg/avatar.png'))
          "
          :src="item.face"
          icon="ios-person"
          size="28"
        />
        <div class="recommendInfo">
          <div class="name">{{ item.nick_name || "匿名用户" }}</div>
          <div class="fans">{{ item.fans }}粉丝</div>
          <div>{{ item.content }}</div>
        </div>
      </div>
      <div class="follow" @click="handleFocus(item)">
        <span>{{ item.focus == "0" ? "+关注" : "已关注" }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { usactivity, followUser } from "@/api/community";
export default {
  props: {
    classData: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {
      selectList: [],
      myjoinlist: [],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    // 关注
    handleFocus(item) {
      console.log(item, "231221312");
      this.followUser(item);
    },
    followUser(e) {
      console.log(e, "eeeeeee=====");
      followUser({
        mid: JSON.parse(localStorage.userInfo).id,
        foucsid: e.aouthid,
        type: e.focus == 1 ? 0 : 1, // 0 取消， 1 关注
      }).then((res) => {
        if (res.code == 1) {
          this.$emit("addfriend");
          console.log("看看");
          // this.getList()
        }
      });
    },
    // 以上全是关注
    // 跳转至对应的好友列表
    gotoMypage(item) {
      this.$router.push(
        {
          path: "/personalpage",
          query: item,
        }
        // console.log()
      );
    },
    getList() {
      usactivity({
        mid: JSON.parse(localStorage.userInfo).id,
        page: 1,
        pagesize: 10,
      }).then((res) => {
        // console.log(res,'我参加的活动');
        for (let i = 0; i < 3; i++) {
          this.myjoinlist.push(res.data[i]);
          // console.log(this.myjoinlist,'我参加的活动');
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.recommendList {
  .recommendItem {
    width: 90%;
    margin: 0 auto;
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #eee;
    .recommend {
      display: flex;
      // justify-content: space-between;
      .recommendInfo {
        .name {
          font-weight: bold;
        }
        .fans {
          text-align: center;
          font-size: 8px;
          border-radius: 3px;
        }
      }
      .header-img {
        width: 40px;
        height: 40px;
        border-radius: 50%;
      }
    }
    .follow {
      cursor: pointer;
      width: 40px;
      height: 20px;
      line-height: 20px;
      text-align: center;
      color: #f00;
      margin-right: 20px;
      border-radius: 10px;
    }
  }
}
</style>
